1 module std.vita.netdb; 2 version(PSVita): 3 import std.vita.netinet_in; 4 import std.vita.socket; 5 extern(C): 6 nothrow @nogc: 7 8 /* 9 * Copyright (c) 2016, 2017, 2018 vitasdk 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. Neither the name of the copyright holder nor the names of its 21 * contributors may be used to endorse or promote products derived from 22 * this software without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 * "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 30 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 */ 36 37 38 struct hostent { 39 char *h_name; 40 char **h_aliases; 41 int h_addrtype; 42 int h_length; 43 char **h_addr_list; 44 45 auto h_addr(){return h_addr_list[0]; } 46 }; 47 48 struct servent { 49 char *s_name; 50 char **s_aliases; 51 int s_port; 52 char *s_proto; 53 } 54 struct protoent 55 { 56 char* p_name; 57 char** p_aliases; 58 int p_proto; 59 } 60 servent* getservbyport(int port, const char* proto){return null; } //Not available 61 62 63 struct addrinfo { 64 int ai_flags; 65 int ai_family; 66 int ai_socktype; 67 int ai_protocol; 68 size_t ai_addrlen; 69 char *ai_canonname; 70 sockaddr *ai_addr; 71 addrinfo *ai_next; 72 } 73 74 /* Error return codes from getaddrinfo() */ 75 enum EAI_BADFLAGS = -1; /* Invalid value for `ai_flags' field. */ 76 enum EAI_NONAME = -2; /* NAME or SERVICE is unknown. */ 77 enum EAI_AGAIN = -3; /* Temporary failure in name resolution. */ 78 enum EAI_FAIL = -4; /* Non-recoverable failure in name res. */ 79 enum EAI_NODATA = -5; /* No address associated with NAME. */ 80 enum EAI_FAMILY = -6; /* `ai_family' not supported. */ 81 enum EAI_SOCKTYPE = -7; /* `ai_socktype' not supported. */ 82 enum EAI_SERVICE = -8; /* SERVICE not supported for `ai_socktype'. */ 83 enum EAI_ADDRFAMILY = -9; /* Address family for NAME not supported. */ 84 enum EAI_MEMORY = -10; /* Memory allocation failure. */ 85 enum EAI_SYSTEM = -11; /* System error returned in `errno'. */ 86 87 enum EAI_OVERFLOW = -12; /* Argument buffer overflow. */ 88 enum EAI_INPROGRESS = -100; /* Processing request in progress. */ 89 enum EAI_CANCELED = -101; /* Request canceled. */ 90 enum EAI_NOTCANCELED = -102; /* Request not canceled. */ 91 enum EAI_ALLDONE = -103; /* All requests done. */ 92 enum EAI_INTR = -104; /* Interrupted by a signal. */ 93 enum EAI_IDN_ENCODE = -105; /* IDN encoding failed. */ 94 95 /* Flag values for getaddrinfo() */ 96 enum AI_PASSIVE = 0x00000001; /* Get address to use bind() */ 97 enum AI_CANONNAME = 0x00000002; /* Fill ai_canonname */ 98 enum AI_NUMERICHOST = 0x00000004; /* Prevent name resolution */ 99 enum AI_NUMERICSERV = 0x00000008; /* Fon't use name resolution. */ 100 101 /* Valid flags for addrinfo */ 102 enum AI_MASK = (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_ADDRCONFIG); 103 enum AI_ALL = 0x00000100; /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ 104 enum AI_V4MAPPED_CFG = 0x00000200; /* Accept IPv4-mapped if kernel supports */ 105 enum AI_ADDRCONFIG = 0x00000400; /* Only if any address is assigned */ 106 enum AI_V4MAPPED = 0x00000800; /* Accept IPv4-mapped IPv6 address */ 107 108 /* Constants for getnameinfo() */ 109 enum NI_MAXHOST = 1025; 110 enum NI_MAXSERV = 32; 111 112 /* Flag values for getnameinfo() */ 113 enum NI_NOFQDN = 0x00000001; 114 enum NI_NUMERICHOST = 0x00000002; 115 enum NI_NAMEREQD = 0x00000004; 116 enum NI_NUMERICSERV = 0x00000008; 117 enum NI_DGRAM = 0x00000010; 118 enum NI_WITHSCOPEID = 0x00000020; 119 120 hostent *gethostbyname(const char *name); 121 hostent *gethostbyaddr(const void *addr, socklen_t len, int type); 122 servent *getservbyname(const char *name, const char *proto); 123 const(char)* gai_strerror(int); 124 int getaddrinfo(const char *node, const char *service, const addrinfo *hints, addrinfo **res); 125 void freeaddrinfo(addrinfo *res);